//
//  GameDetailPageViewController.m
//  Vlink
//
//  Created by 赵隆杰 on 2021/10/9.
//  Copyright © 2021 myTV. All rights reserved.
//

#import "GameDetailPageViewController.h"
#import "GameDetailCommentListViewController.h"
#import "GameStrategyViewController.h"

@interface GameDetailPageViewController ()

@property (nonatomic, strong) UIView *storeMenuView;

@property (nonatomic, strong, ) NSArray <GameDetailClassifyModel *>*classifyList;
@property (nonatomic, copy) NSString *colorStr;

@end

@implementation GameDetailPageViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.naviView.hidden = YES;
}

-(instancetype)init
{
    self = [super init];
    if (self) {
        self.titleColorSelected = kThemeTitleColor;
        self.titles = @[@"详情",@"评论",@"交易",@"开服表"];
        
        self.menuViewStyle = WMMenuViewStyleLine;
        self.titleSizeNormal  = 16;
        self.titleColorNormal = kColor333333;
        self.progressColor = kThemeTitleColor;
        self.progressHeight = 5;
        self.progressWidth = 10;
        self.progressViewCornerRadius = 2.5;
    }
    return self;
}

- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return self.titles.count;
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    if (index == 0) {
        GameStrategyViewController *vc = [[GameStrategyViewController alloc] init];
        vc.viewModel = self.viewModel;
        return vc;
    } else {
        GameDetailCommentListViewController *vc = [[GameDetailCommentListViewController alloc] initWithGameId:self.viewModel.detailModel.gameId];
        
        return vc;
    }
    
}

- (void)pageController:(WMPageController *)pageController willEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info
{
    NSInteger index = [info[@"index"] integerValue];
    if (self.pageIndexBlock) {
        self.pageIndexBlock(index);
    }
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    return self.titles[index];
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView
{
    return CGRectMake(0, 0, self.view.width, 44);
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView
{
    CGFloat originY = CGRectGetMaxY([self pageController:pageController preferredFrameForMenuView:self.menuView]);
    return CGRectMake(0, originY, SL_WINDOW_WIDTH, self.view.height - originY);
}

- (UIView *)menuView:(WMMenuView *)menu badgeViewAtIndex:(NSInteger)index
{
    if (index == 1) {
        UIView *badgeView = [[UIView alloc] init];
        badgeView.backgroundColor = kColor(@"F94E4D");
        badgeView.frame = CGRectMake(self.menuItemWidth/2, 0, 0, 18);
        badgeView.layer.cornerRadius = badgeView.height/2;
        badgeView.layer.masksToBounds = YES;
        UILabel *badgeLabel = [[UILabel alloc] init];
        badgeLabel.frame = CGRectMake(5, 0, badgeView.width, badgeView.height);
        badgeLabel.text = @"999";
        badgeLabel.textColor = [UIColor whiteColor];
        badgeLabel.font = [UIFont systemFontOfSize:12];
        [badgeView addSubview:badgeLabel];
        CGFloat width = ceil([badgeLabel.text boundingRectWithSize:CGSizeMake(MAXFLOAT, badgeLabel.height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: badgeLabel.font} context:nil].size.width);
        badgeLabel.width = width;
        badgeView.width = badgeLabel.width + 10;
        return badgeView;
    }
    return nil;
}

@end
